import { GET_ALL_ORDER, GET_LOGISTICS_INFO, MODIFY_ORDER_STATUS } from '@/store/order/const'
import { Commit } from 'vuex'
import { GetAllOder, getAllOder, getLogisticsInfo, modifyOrderStatus } from '@/api/order'
import { order } from '@/store/order/intereface'

export default {
  async [GET_ALL_ORDER] (context:{commit:Commit}, params:GetAllOder) {
    const { data: { goods, total } } = await getAllOder(params)
    context.commit(GET_ALL_ORDER, {
      data: goods,
      count: total
    })
  },

  async [MODIFY_ORDER_STATUS] (context:{commit:Commit}, data:order) {
    const result = { ...data }
    result.order_pay = data.order_pay === '1' ? '0' : '1'
    const { meta, data: res } = await modifyOrderStatus(result)
    if (meta.status === 201) context.commit(MODIFY_ORDER_STATUS, result)
  },

  async [GET_LOGISTICS_INFO] (context:{commit:Commit}, id:number) {
    const { meta: { status, msg }, data } = await getLogisticsInfo(id)
    console.log(status, msg)
  }
}
